package com.cypher.encryptionanddecryption.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.cypher.encryptionanddecryption.R;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  蓝牙信息列表适配器
 */
public class BluetoothTalkAdapter extends BaseAdapter {

    /**
     * 存放蓝夜通信内容的集合
     */
    private List<String> contents;
    public List<String> getContents() {
        return contents;
    }
    public void setContents(List<String> contents) {
        this.contents = contents;
    }
    private Context context;
    public BluetoothTalkAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return contents.size();
    }

    @Override
    public Object getItem(int position) {
        return contents.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    class ViewHolder {
        TextView contentText;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.fragment_bluetooth_talk_item, parent, false);
            viewHolder.contentText = convertView.findViewById(R.id.talk_content_txt);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.contentText.setText(contents.get(position));
        return convertView;
    }
}
